<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div id="app">
    <input type="file" @change="changeImg"/>
    <button @click="upload">Vue 上传</button>
</div>
</body>
</html>
<script src="js/vue.min.js"></script>
<script src="js/axios.min.js"></script>
<script>
    new Vue({
        el: '#app',
        data: {
            file: null
        },
        methods: {
            changeImg(event) {
                this.file = event.target.files[0]
            },
            upload() {
                // 表单数据
                let data = new FormData();
                data.append('file', this.file);
                // 定义发送格式
                let type = {
                    headers: {
                        'Content-Type': 'multipart/form-data'
                    }
                }
                axios.post('upload', data, type)
                    .then((response) => {
                        console.log(response.data)
                    });
            }
        }
    });
</script>